<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/views/global/taglibs.jsp" %>
<!DOCTYPE>
<html>
  <head>
    <base href="<%=basePath %>">
    <title>编辑 - 定时钟</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
	<%@include file="/views/global/include.jsp" %>
	
  </head>
  
  <body>
 	<div class="main-md">
		<form id="updateForm" class="form-horizontal validate" role="form">
			<input type="hidden" name="id" value="${entry.id }"/>
			<div id="msg"></div>
			<div class="form-group padding10">
				<label class="col-sm-2 control-label" for="jobName">Job Name:</label>
				<div class="col-sm-4">
					<input type="text" class="form-control" id="jobName" name="jobName" value="${entry.jobName }"
						placeholder="Please input unique job name" required="Job name can't be empty."/>
				</div>
				<span class="error"></span>
			</div>
			<div class="form-group padding10">
 				<label class="col-sm-2 control-label" for="jobClass">Job Class:</label>
				<div class="col-sm-7">
					<input type="text" class="form-control" id="jobClass" name="jobClass" value="${entry.jobClass }"
						 placeholder="Full class name for job implemention" 
						 required="Job class name can't be empty." />
				</div>
				<span class="error"></span>
			</div>
			<div class="form-group padding10">
 				<label class="col-sm-2 control-label" for="cronText">CronText:</label>
				<div class="col-sm-7">
					<input type="text" class="form-control" id="cronText" name="cronText" value="${entry.cronText }"
						 placeholder="Crontab Text" 
						 required="CronText can't be empty." />
				</div>
				<span class="error"></span>
			</div>
			<div class="form-group padding10">
 				<label class="col-sm-2 control-label" for="sortNo">Sort No:</label>
				<div class="col-sm-7">
					<input type="text" class="form-control" id="sortNo" name="sortNo" value="${entry.sortNo }"
						 placeholder="Sort No." digits="true"/>
				</div>
				<span class="error"></span>
			</div>
			<div class="form-group padding10">
 				<label class="col-sm-2 control-label" for="dependNames">Depend Names:</label>
				<div class="col-sm-7">
					<textarea rows="4" cols="50" class="form-control" name="dependNames"
						placeholder="Many items please split by [,]">${entry.dependNames }</textarea>
				</div>
				<span class="error"></span>
			</div>
			<div class="form-group padding10">
 				<label class="col-sm-2 control-label" for="comments">Comments:</label>
				<div class="col-sm-7">
					<textarea rows="4" cols="50" class="form-control" name="comments"
						placeholder="Many items please split by [,]">${entry.comments }</textarea>
				</div>
				<span class="error"></span>
			</div>
			<div class="form-group padding10">
				<label class="col-sm-2 control-label" for="effect"> Effect Now:</label>
				<div class="col-sm-10 form-inline">
					<input type="checkbox" class="checkbox" id="effect" name="effect" value="1" checked="checked"/>
				</div>
			</div>
			<div class="form-group padding10">
				<div class="col-sm-2"></div>
				<div class="col-sm-4">
					<button type="button" class="btn btn-info" onclick="javascript:saveNode(this)">Save</button>
					<c:if test="${not empty entry.jobName }">
						<button type="button" class="btn btn-info" onclick="javascript:deleteNode(this, ${entry.id}, '${entry.jobName }')">Delete</button>
					</c:if>
				</div>
			</div>
		</form>
		<form id="itemForm"></form>
 	</div>
 	<%@include file="/views/global/AdminScripts.jsp" %>
  </body>
<script type="text/javascript">
$(document).ready(function(){
	
});

function saveNode(){
	var validator = $("#updateForm").validate({meta:"validate"});
	if(validator.form()){
		$("#updateForm").goAjax({semantic: false, checkLogin: true,
			url: "dev/scheduler/save",
			data:{},
			success: function(jsonData) {
				if(true == jsonData.success){
       				$("#msg").alert({type:'alert-success', text: '保存成功！'});
       				$("#updateForm")[0].reset();
       				if(null != parent.parent.document.dialog){
       					parent.parent.GB_hide();
       				}
       			} else {
       				$("#msg").alert({type:'alert-danger', text: '保存失败: ' + jsonData.message});
       			}
			}
		});
	}
}

function deleteNode(target, objId, jobName){
	$("#itemForm").goAjax({semantic: false, checkLogin: true,
		url: "dev/scheduler/delete",
		data:{id: objId, jobName: jobName, effect: $("#effect").val()},
		success: function(jsonData) {
			if(true == jsonData.success){
   				$("#msg").alert({type:'alert-success', text: '保存成功！'});
   				$("#updateForm")[0].reset();
   				if(null != parent.parent.document.dialog){
   					parent.parent.GB_hide();
   				}
   			} else {
   				$("#msg").alert({type:'alert-danger', text: '保存失败: ' + jsonData.message});
   			}
		}
	});
}
</script>
</html>
